from flask import Blueprint,jsonify,request
from db import db1
import json

bp_cbf = Blueprint('cflask',__name__)


@bp_cbf.route('/yw',methods=['POST','GET'])
def yw():
    if request.method == 'POST':
        data = request.data
        if data:
            data = json.loads(data)
        else:
            data = request.form
        sql = """insert into yw values (%d,'%s','%s')"""%(0,data['name'],'')
        db1.insert(sql)
        return jsonify({'code':200})
    elif request.method == 'GET':
        sql = """select * from yw"""
        list = db1.find_all(sql)
        return jsonify({'code':200,"list":list})
